$(function () {
    $("#jqGrid").jqGrid({
        url: '../bpmnoderule/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true },
			{ label: '父键', name: 'pid', index: 'pid', width: 80 }, 			
			{ label: '模板id', name: 'bpmModleId', index: 'bpm_modle_id', width: 80 }, 			
			{ label: '节点id', name: 'bpmModleNodeId', index: 'bpm_modle_node_id', width: 80 }, 			
			{ label: '部署id', name: 'bpmDeploymentId', index: 'bpm_deployment_id', width: 80 }, 			
			{ label: '部署成功流程定义Id', name: 'bpmProcessDefinitionId', index: 'bpm_process_definition_id', width: 80 }, 			
			{ label: '规则名称', name: 'ruleName', index: 'rule_name', width: 80 }, 			
			{ label: '规则类型b:按钮，e:环境变量，p:选择参与者，s:执行脚本', name: 'ruleType', index: 'rule_type', width: 80 }, 			
			{ label: '排序', name: 'ruleOrder', index: 'rule_order', width: 80 }, 			
			{ label: '流程环境变量名', name: 'bpmEnvName', index: 'bpm_env_name', width: 80 }, 			
			{ label: '流程环境变量值', name: 'bpmEnvValue', index: 'bpm_env_value', width: 80 }, 			
			{ label: '流程参与人设置XX[R]:设置确实，xx[O]:设置机构、xx[P]：设置人员', name: 'bpmPartyName', index: 'bpm_party_name', width: 80 }, 			
			{ label: '流程参与人设置的值，逗号分割', name: 'bpmPartyValue', index: 'bpm_party_value', width: 80 }			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		bpmNodeRule: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.bpmNodeRule = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.bpmNodeRule.id == null ? "../bpmnoderule/save" : "../bpmnoderule/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.bpmNodeRule),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../bpmnoderule/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../bpmnoderule/info/"+id, function(r){
                vm.bpmNodeRule = r.bpmNodeRule;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});